/**
 * Created by L.jp
 * Description:https://leetcode-cn.com/problems/symmetric-tree/
 * User: 86189
 * Date: 2021-10-10
 * Time: 16:12
 */
class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) {
          this.val = val;
      }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
}
public class BinaryTree {
    //测试函数，光有一个root参数是实现不了的，所以必须再创建一个函数去实现
    public boolean isSymmetric(TreeNode root){
        return check(root, root);
    }
    //实现函数，判断是否对称
    public boolean check(TreeNode p, TreeNode q) {
        if (p == null && q == null) {
            return true;
        }
        if (p == null || q == null) {
            return false;
        }
        //要求左树的左树和右树的右树值相等，左树的右树和右树的左树值相等
        return p.val == q.val && check(p.left, q.right) && check(p.right, q.left);
    }

}
